package com.fly.demo.restful;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.transaction.annotation.Transactional;

import com.fly.demo.service.UserService;

import lombok.extern.slf4j.Slf4j;

/**
 * 
 * see: https://blog.csdn.net/weixin_31774841/article/details/115060365
 * 
 * @author 00fly
 * @version [版本号, 2021年10月10日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Slf4j
@ActiveProfiles("test")
@Transactional
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class RestControllerTest2
{
    @Autowired
    UserService userService;
    
    @Autowired
    private MockMvc mockMvc;
    
    /**
     * 测试 RestAPI
     * 
     * @throws Exception
     * 
     * @see [类、类#方法、类#成员]
     */
    @Test
    public void testRestAPI()
        throws Exception
    {
        log.info("★★★★★★★★ userService.queryAll() = {}", userService.queryAll());
        
        // get、post
        mockMvc.perform(MockMvcRequestBuilders.get("/").param("pageNo", "1").param("pageSize", "5")).andDo(MockMvcResultHandlers.print());
        mockMvc.perform(MockMvcRequestBuilders.post("/").param("pageNo", "1").param("pageSize", "10")).andDo(MockMvcResultHandlers.print());
    }
}
